package com.hzsai.service.Impl;

import com.hzsai.dao.UserDAO;
import com.hzsai.mappersa.UserMapper;
import com.hzsai.pojo.User;
import com.hzsai.service.UserService;
import com.hzsai.utils.ResponseMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.List;

@Service
public class UserServiceImpl implements UserService{

    @Autowired
    private UserDAO userDAO;

    @Autowired
    private UserMapper mapper;

    public void say() {
        System.out.printf("UserService...");
    }

    public ResponseMsg insertUser(String username, String password) {

        User user = new User();
        user.setUsername(username);
        user.setPassword(password);
        //User user = null;
        userDAO.insertUser(user);
        //assert(false);

        return ResponseMsg.success();
    }

    @Override
    public ResponseMsg insertUser(User user) {
        userDAO.insertUser(user);
        return ResponseMsg.success();
    }

    //    public ResponseMsg queryUser(String username, String password) {
//        return null;
//    }

    public UserDAO getUserDAO() {
        return userDAO;
    }

    @Override
    public List<User> selectAllUser() throws SQLException {

        return userDAO.selectAllUser();
    }

    @Override
    public List<User> selectPageUser(long current, long size) throws SQLException {
        return userDAO.selectPagaUser(current, size);
    }

    @Override
    public User selectUserById(long id) throws SQLException {
        return userDAO.selectUserById(id);
    }

    @Override
    public List<User> findUsersByIds(List<Integer> ids) {
        List<User> retList = mapper.findUsersByIds(ids);
        return retList;
    }
}
